/*    */ package com.yizhilu.os.image.util;
/*    */ 
/*    */ import java.io.File;
/*    */ import java.io.IOException;
/*    */ import org.springframework.web.multipart.MultipartFile;
/*    */ 
/*    */ public class FileUploadUtil
/*    */ {
/* 13 */   private File uploadDir = null;
/* 14 */   private MultipartFile[] mtpfiles = null;
/*    */   private String FileUrl;
/*    */ 
/*    */   public FileUploadUtil(File uploadDir, MultipartFile[] mtpfiles, String FileUrl)
/*    */   {
/* 19 */     this.uploadDir = uploadDir;
/* 20 */     this.mtpfiles = mtpfiles;
/* 21 */     this.FileUrl = FileUrl;
/*    */   }
/*    */ 
/*    */   public String upload(boolean overwrite)
/*    */     throws IOException
/*    */   {
/* 27 */     checkDir(this.uploadDir);
/* 28 */     File fileUpload = null;
/* 29 */     for (MultipartFile mtpfile : this.mtpfiles) {
/* 30 */       int i = 0;
/*    */ 
/* 32 */       String originalFilename = mtpfile.getOriginalFilename();
/* 33 */       fileUpload = new File(this.uploadDir, originalFilename);
/* 34 */       this.FileUrl = (this.FileUrl + "/" + originalFilename);
/*    */ 
/* 36 */       if ((fileUpload.exists()) && (!overwrite))
/*    */       {
/* 38 */         while (fileUpload.exists())
/*    */         {
/* 40 */           fileUpload = new File(this.uploadDir, originalFilename + i++);
/* 41 */           this.FileUrl = (this.FileUrl + this.FileUrl + originalFilename + ",");
/*    */         }
/*    */       }
/*    */ 
/* 45 */       mtpfile.transferTo(fileUpload);
/*    */     }
/* 47 */     return this.FileUrl;
/*    */   }
/*    */ 
/*    */   private void checkDir(File uploadDir)
/*    */   {
/* 56 */     if (!uploadDir.exists())
/*    */     {
/* 58 */       uploadDir.mkdirs();
/*    */     }
/*    */   }
/*    */ }

/* Location:           F:\work\公司\质量学院\ducumentQIN\项目更新\web\20171122\
 * Qualified Name:     com.yizhilu.os.image.util.FileUploadUtil
 * JD-Core Version:    0.6.1
 */